

using System.Linq;
using Abp.Authorization;
using Abp.Configuration.Startup;
using Abp.Localization;
using Abp.MultiTenancy;
using Yozeev.BusinessLogic.Authorization;
using Yozeev.Authorization;

namespace Yozeev.Authorization
{
    /// <summary>
    /// 权限配置都在这里。
    /// 给权限默认设置服务
    /// See <see cref="CommonCustomerPermissions" /> for all permission names. CommonCustomer
    ///</summary>
    public class CommonCustomerAuthorizationProvider : AuthorizationProvider
    {
        private readonly bool _isMultiTenancyEnabled;

		public CommonCustomerAuthorizationProvider()
		{

		}
		public CommonCustomerAuthorizationProvider(bool isMultiTenancyEnabled)
		{
			_isMultiTenancyEnabled = isMultiTenancyEnabled;
		}



		public CommonCustomerAuthorizationProvider(IMultiTenancyConfig multiTenancyConfig)
        {
            _isMultiTenancyEnabled = multiTenancyConfig.IsEnabled;
        }

		public override void SetPermissions(IPermissionDefinitionContext context)
		{
			// 在这里配置了CommonCustomer 的权限。
			var pages = context.GetPermissionOrNull(AppPermissions.Pages) ?? context.CreatePermission(AppPermissions.Pages, L("Pages"));

			var administration = pages.Children.FirstOrDefault(p => p.Name == AppPermissions.Pages_Administration) ?? pages.CreateChildPermission(AppPermissions.Pages_Administration, L("Administration"));

			var entityPermission = administration.CreateChildPermission(CommonCustomerPermissions.Node , L("CommonCustomer"));
			entityPermission.CreateChildPermission(CommonCustomerPermissions.Query, L("QueryCommonCustomer"));
			entityPermission.CreateChildPermission(CommonCustomerPermissions.Create, L("CreateCommonCustomer"));
			entityPermission.CreateChildPermission(CommonCustomerPermissions.Edit, L("EditCommonCustomer"));
			entityPermission.CreateChildPermission(CommonCustomerPermissions.Delete, L("DeleteCommonCustomer"));
			entityPermission.CreateChildPermission(CommonCustomerPermissions.BatchDelete, L("BatchDeleteCommonCustomer"));
			entityPermission.CreateChildPermission(CommonCustomerPermissions.ExportExcel, L("ExportToExcel"));

			
							//// custom codes
									
							

							//// custom codes end
		}

		private static ILocalizableString L(string name)
		{
			return new LocalizableString(name, AppConsts.LocalizationSourceName);
		}
    }
}